package com.example.culturapp;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import android.R.layout;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ExpandableListView;
import android.widget.RatingBar;
import android.widget.TextView;

public class PlaceholderFragmentRumores extends Fragment {
	protected ItemAdapter newlistAdapter;
	protected ExpandableListView listView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
		Bundle savedInstanceState) {
	//View result =super.onCreateView(inflater, container, savedInstanceState);
	//Context context= container.getContext();
	//LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	View result =inflater.inflate(R.layout.rumores_activity_main,container,false);
	
	listView = (ExpandableListView) result.findViewById(R.id.listViewexp);
	TextView tvContenido= (TextView) result.findViewById(R.id.tvContenido);
	RatingBar rating= (RatingBar) result.findViewById(R.id.rbRating);
	Button btnValorar= (Button) result.findViewById(R.id.btnValorar);
	if(savedInstanceState!=null){
		//String jsonMyObject;
		//jsonMyObject = savedInstanceState.getString("myObject");
		//Gson gson = new GsonBuilder().create();
		//Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
		newlistAdapter = new ItemAdapter(getActivity(), tvContenido, rating, btnValorar, Model.getInstance());
		//newlistAdapter = gson.fromJson(jsonMyObject, ItemAdapter.class);
		/*newlistAdapter.activity=getActivity();
		newlistAdapter.btnValorar=btnValorar;
		newlistAdapter.rbRating=rating;
		newlistAdapter.tvContenido=tvContenido;
		newlistAdapter.inflater= getActivity().getLayoutInflater();
		newlistAdapter.md= Model.getInstance();*/
	}else{
	if(newlistAdapter!=null){
	newlistAdapter.btnValorar=btnValorar;
	newlistAdapter.rbRating=rating;
	newlistAdapter.tvContenido=tvContenido;
	}
	}
	//ItemAdapter adapter = new adaptador(this, grupos, tvContenido, rating, btnValorar);
	if(listView!=null)
	listView.setAdapter(newlistAdapter);
	else 
		return result;
	return result;
}
	
	@Override
	public void onResume() {
		super.onResume();
		//if(listView!=null)
		//	listView.setAdapter(newlistAdapter);
		//this.getListView().setAdapter(newlistAdapter);
		/*this.getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> adapter, View view,
					int position, long arg) {
				Item item = (Item) listAdapter.getItem(position);
				
				//intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				if(view.getContext()!=null){
					Intent intent = new Intent(view.getContext(), MostrarEventoActivity.class);//*******
					intent.putExtra("image",item.getImage());
					intent.putExtra("title",item.getTitle());
					intent.putExtra("url",item.getUrl());
					view.getContext().startActivity(intent);
				}else{
					Log.d(null, "***************************NULL");
				}
			};

		});
	;*/
	}
	@Override
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		//Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
		//outState.putString("myObject", gson.toJson(newlistAdapter));
		outState.putString("myObject", "x");
	}
}
